package com.bianmaba.example.eacache;

import net.sf.ehcache.event.CacheEventListener;
import net.sf.ehcache.event.CacheEventListenerFactory;
import net.sf.ehcache.util.PropertyUtil;

import java.util.Properties;

/**
 * @program: example-web-framework-extends
 * @description:
 * @author: Chenjiabin
 * @create: 2018-04-21 18:16
 **/
public class DefaultCacheEventListenerFactory extends CacheEventListenerFactory {
    @Override
    public CacheEventListener createCacheEventListener(Properties properties) {
        boolean enabled = isEnabled(properties);
        return new DefaultCacheEventListener(enabled);
    }


    protected boolean isEnabled(Properties properties) {
        String enabledString = PropertyUtil.extractAndLogProperty("enabled", properties);
        boolean enabled;
        if (enabledString != null) {
            enabled = PropertyUtil.parseBoolean(enabledString);
        } else {
            enabled = true;
        }

        return enabled;
    }
}
